<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>tf::Taskflow class | Taskflow QuickStart</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
  <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
  <link rel="icon" href="favicon.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta name="theme-color" content="#22272e" />
</head>
<body>
<header><nav id="navigation">
  <div class="m-container">
    <div class="m-row">
      <span id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">
        <a href="https://taskflow.github.io"><img src="taskflow_logo.png" alt="" />Taskflow</a> <span class="m-breadcrumb">|</span> <a href="index.html" class="m-thin">QuickStart</a>
      </span>
      <div class="m-col-t-4 m-hide-m m-text-right m-nopadr">
        <a href="#search" class="m-doc-search-icon" title="Search" onclick="return showSearch()"><svg style="height: 0.9rem;" viewBox="0 0 16 16">
          <path id="m-doc-search-icon-path" d="m6 0c-3.31 0-6 2.69-6 6 0 3.31 2.69 6 6 6 1.49 0 2.85-0.541 3.89-1.44-0.0164 0.338 0.147 0.759 0.5 1.15l3.22 3.79c0.552 0.614 1.45 0.665 2 0.115 0.55-0.55 0.499-1.45-0.115-2l-3.79-3.22c-0.392-0.353-0.812-0.515-1.15-0.5 0.895-1.05 1.44-2.41 1.44-3.89 0-3.31-2.69-6-6-6zm0 1.56a4.44 4.44 0 0 1 4.44 4.44 4.44 4.44 0 0 1-4.44 4.44 4.44 4.44 0 0 1-4.44-4.44 4.44 4.44 0 0 1 4.44-4.44z"/>
        </svg></a>
        <a id="m-navbar-show" href="#navigation" title="Show navigation"></a>
        <a id="m-navbar-hide" href="#" title="Hide navigation"></a>
      </div>
      <div id="m-navbar-collapse" class="m-col-t-12 m-show-m m-col-m-none m-right-m">
        <div class="m-row">
          <ol class="m-col-t-6 m-col-m-none">
            <li><a href="pages.html">Handbook</a></li>
            <li><a href="namespaces.html">Namespaces</a></li>
          </ol>
          <ol class="m-col-t-6 m-col-m-none" start="3">
            <li><a href="annotated.html">Classes</a></li>
            <li><a href="files.html">Files</a></li>
            <li class="m-show-m"><a href="#search" class="m-doc-search-icon" title="Search" onclick="return showSearch()"><svg style="height: 0.9rem;" viewBox="0 0 16 16">
              <use href="#m-doc-search-icon-path" />
            </svg></a></li>
          </ol>
        </div>
      </div>
    </div>
  </div>
</nav></header>
<main><article>
  <div class="m-container m-container-inflatable">
    <div class="m-row">
      <div class="m-col-l-10 m-push-l-1">
        <h1>
          <span class="m-breadcrumb"><a href="namespacetf.html">tf</a>::<wbr/></span>Taskflow <span class="m-thin">class</span>
        </h1>
        <p>class to create a taskflow object</p>
        <nav class="m-block m-default">
          <h3>Contents</h3>
          <ul>
            <li>
              Reference
              <ul>
                <li><a href="#base-classes">Base classes</a></li>
                <li><a href="#typeless-methods">Constructors, destructors, conversion operators</a></li>
                <li><a href="#pub-methods">Public functions</a></li>
              </ul>
            </li>
          </ul>
        </nav>
<p>A taskflow manages a task dependency graph where each task represents a callable object (e.g., <a href="https://en.cppreference.com/w/cpp/language/lambda">lambda</a>, <a href="https://en.cppreference.com/w/cpp/utility/functional/function">std::<wbr />function</a>) and an edge represents a dependency between two tasks. A task is one of the following types:</p><ol><li>static task : the callable constructible from <code>std::function&lt;void()&gt;</code></li><li>subflow task : the callable constructible from <code>std::function&lt;void(tf::Subflow&amp;)&gt;</code></li><li>condition task : the callable constructible from <code>std::function&lt;int()&gt;</code></li><li>multi-condition task: the callable constructible from <code>std::function&lt;tf::SmallVector&lt;int&gt;()&gt;</code></li><li>module task : the task constructed from <a href="classtf_1_1FlowBuilder.html#ac6f22228d4c2ea2e643c4b0d42c0e92a" class="m-doc">tf::<wbr />Taskflow::<wbr />composed_of</a> <code>std::function&lt;void(tf::Runtime&amp;)&gt;</code></li></ol><p>Each task is a basic computation unit and is run by one worker thread from an executor. The following example creates a simple taskflow graph of four static tasks, <code>A</code>, <code>B</code>, <code>C</code>, and <code>D</code>, where <code>A</code> runs before <code>B</code> and <code>C</code> and <code>D</code> runs after <code>B</code> and <code>C</code>.</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Executor</span><span class="w"> </span><span class="n">executor</span><span class="p">;</span>
<span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span><span class="w"> </span><span class="n">taskflow</span><span class="p">(</span><span class="s">&quot;simple&quot;</span><span class="p">);</span>

<span class="n">tf</span><span class="o">::</span><span class="n">Task</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](){</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;TaskA</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">});</span>
<span class="n">tf</span><span class="o">::</span><span class="n">Task</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](){</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;TaskB</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">});</span>
<span class="n">tf</span><span class="o">::</span><span class="n">Task</span><span class="w"> </span><span class="n">C</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](){</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;TaskC</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">});</span>
<span class="n">tf</span><span class="o">::</span><span class="n">Task</span><span class="w"> </span><span class="n">D</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](){</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;TaskD</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">});</span>

<span class="n">A</span><span class="p">.</span><span class="n">precede</span><span class="p">(</span><span class="n">B</span><span class="p">,</span><span class="w"> </span><span class="n">C</span><span class="p">);</span><span class="w">  </span><span class="c1">// A runs before B and C</span>
<span class="n">D</span><span class="p">.</span><span class="n">succeed</span><span class="p">(</span><span class="n">B</span><span class="p">,</span><span class="w"> </span><span class="n">C</span><span class="p">);</span><span class="w">  </span><span class="c1">// D runs after  B and C</span>

<span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">).</span><span class="n">wait</span><span class="p">();</span></pre><p>The taskflow object itself is NOT thread-safe. You should not modifying the graph while it is running, such as adding new tasks, adding new dependencies, and moving the taskflow to another. To minimize the overhead of task creation, our runtime leverages a global object pool to recycle tasks in a thread-safe manner.</p><p>Please refer to <a href="Cookbook.html" class="m-doc">Cookbook</a> to learn more about each task type and how to submit a taskflow to an executor.</p>
        <section id="base-classes">
          <h2><a href="#base-classes">Base classes</a></h2>
          <dl class="m-doc">
            <dt>
              class <a href="classtf_1_1FlowBuilder.html" class="m-doc">FlowBuilder</a>
            </dt>
            <dd>class to build a task dependency graph</dd>
          </dl>
        </section>
        <section id="typeless-methods">
          <h2><a href="#typeless-methods">Constructors, destructors, conversion operators</a></h2>
          <dl class="m-doc">
            <dt>
              <span class="m-doc-wrap-bumper"><a href="#a7242a74dcb16731b4e40816647b93305" class="m-doc">Taskflow</a>(</span><span class="m-doc-wrap">const <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a>&amp; name)</span>
            </dt>
            <dd>constructs a taskflow with the given name</dd>
            <dt id="ade7fc641d136a3f8c96682c08040626a">
              <span class="m-doc-wrap-bumper"><a href="#ade7fc641d136a3f8c96682c08040626a" class="m-doc-self">Taskflow</a>(</span><span class="m-doc-wrap">)</span>
            </dt>
            <dd>constructs a taskflow</dd>
            <dt>
              <span class="m-doc-wrap-bumper"><a href="#afd790de6db6d16ddf4729967c1edebb5" class="m-doc">Taskflow</a>(</span><span class="m-doc-wrap"><a href="classtf_1_1Taskflow.html" class="m-doc">Taskflow</a>&amp;&amp; rhs)</span>
            </dt>
            <dd>constructs a taskflow from a moved taskflow</dd>
            <dt>
              <span class="m-doc-wrap-bumper"><a href="#aa966a69493ecc8ecb9131ef3c5354b8e" class="m-doc">~Taskflow</a>(</span><span class="m-doc-wrap">) <span class="m-label m-flat m-info">defaulted</span></span>
            </dt>
            <dd>default destructor</dd>
          </dl>
        </section>
        <section id="pub-methods">
          <h2><a href="#pub-methods">Public functions</a></h2>
          <dl class="m-doc">
            <dt>
              <span class="m-doc-wrap-bumper">auto <a href="#aa4957a41e63e1d1a6f77c540d70d04fa" class="m-doc">operator=</a>(</span><span class="m-doc-wrap"><a href="classtf_1_1Taskflow.html" class="m-doc">Taskflow</a>&amp;&amp; rhs) -&gt; <a href="classtf_1_1Taskflow.html" class="m-doc">Taskflow</a>&amp;</span>
            </dt>
            <dd>move assignment operator</dd>
            <dt>
              <span class="m-doc-wrap-bumper">void <a href="#ac433018262e44b12c4cc9f0c4748d758" class="m-doc">dump</a>(</span><span class="m-doc-wrap"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html" class="m-doc-external">std::<wbr />ostream</a>&amp; ostream) const</span>
            </dt>
            <dd>dumps the taskflow to a DOT format through a <a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html" class="m-doc-external">std::<wbr />ostream</a> target</dd>
            <dt>
              <span class="m-doc-wrap-bumper">auto <a href="#a9c4900da1831dce708664a06b3e3a3fb" class="m-doc">dump</a>(</span><span class="m-doc-wrap">) const -&gt; <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a></span>
            </dt>
            <dd>dumps the taskflow to a <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a> of DOT format</dd>
            <dt id="af4f03bca084deb5c2228ac8936d33649">
              <span class="m-doc-wrap-bumper">auto <a href="#af4f03bca084deb5c2228ac8936d33649" class="m-doc-self">num_tasks</a>(</span><span class="m-doc-wrap">) const -&gt; size_t</span>
            </dt>
            <dd>queries the number of tasks</dd>
            <dt>
              <span class="m-doc-wrap-bumper">auto <a href="#a224301842d94c44fd7fe99d8ac2ba241" class="m-doc">empty</a>(</span><span class="m-doc-wrap">) const -&gt; bool</span>
            </dt>
            <dd>queries the emptiness of the taskflow</dd>
            <dt>
              <span class="m-doc-wrap-bumper">void <a href="#ad5706e5819aa01a63c4aa2e3485546b9" class="m-doc">name</a>(</span><span class="m-doc-wrap">const <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a>&amp;)</span>
            </dt>
            <dd>assigns a name to the taskflow</dd>
            <dt>
              <span class="m-doc-wrap-bumper">auto <a href="#a911edd95acc1322433bddfcfeaf2ccb0" class="m-doc">name</a>(</span><span class="m-doc-wrap">) const -&gt; const <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a>&amp;</span>
            </dt>
            <dd>queries the name of the taskflow</dd>
            <dt>
              <span class="m-doc-wrap-bumper">void <a href="#a1f00bbe72a1553c9656ecae4d98bb9af" class="m-doc">clear</a>(</span><span class="m-doc-wrap">)</span>
            </dt>
            <dd>clears the associated task dependency graph</dd>
            <dt>
              <div class="m-doc-template">template&lt;typename V&gt;</div>
              <span class="m-doc-wrap-bumper">void <a href="#a6350d0d6653ae9ae7b94c35e42fffe07" class="m-doc">for_each_task</a>(</span><span class="m-doc-wrap">V&amp;&amp; visitor) const</span>
            </dt>
            <dd>applies a visitor to each task in the taskflow</dd>
            <dt>
              <span class="m-doc-wrap-bumper">void <a href="#a354a7673fabeaf3be66928ad6b573900" class="m-doc">remove_dependency</a>(</span><span class="m-doc-wrap"><a href="classtf_1_1Task.html" class="m-doc">Task</a> from,
              <a href="classtf_1_1Task.html" class="m-doc">Task</a> to)</span>
            </dt>
            <dd>removes dependencies that go from task <code>from</code> to task <code>to</code></dd>
            <dt>
              <span class="m-doc-wrap-bumper">auto <a href="#a8da984d149b439e88468bf26e02ecf27" class="m-doc">graph</a>(</span><span class="m-doc-wrap">) -&gt; <a href="classtf_1_1Graph.html" class="m-doc">Graph</a>&amp;</span>
            </dt>
            <dd>returns a reference to the underlying graph object</dd>
          </dl>
        </section>
        <section>
          <h2>Function documentation</h2>
          <section class="m-doc-details" id="a7242a74dcb16731b4e40816647b93305"><div>
            <h3>
              <span class="m-doc-wrap-bumper"> tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a7242a74dcb16731b4e40816647b93305" class="m-doc-self">Taskflow</a>(</span><span class="m-doc-wrap">const <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a>&amp; name)</span></span>
            </h3>
            <p>constructs a taskflow with the given name</p>
<pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span><span class="w"> </span><span class="n">taskflow</span><span class="p">(</span><span class="s">&quot;My Taskflow&quot;</span><span class="p">);</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">name</span><span class="p">();</span><span class="w">         </span><span class="c1">// &quot;My Taskflow&quot;</span></pre>
          </div></section>
          <section class="m-doc-details" id="afd790de6db6d16ddf4729967c1edebb5"><div>
            <h3>
              <span class="m-doc-wrap-bumper"> tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#afd790de6db6d16ddf4729967c1edebb5" class="m-doc-self">Taskflow</a>(</span><span class="m-doc-wrap"><a href="classtf_1_1Taskflow.html" class="m-doc">Taskflow</a>&amp;&amp; rhs)</span></span>
            </h3>
            <p>constructs a taskflow from a moved taskflow</p>
<p>Constructing a taskflow <code>taskflow1</code> from a moved taskflow <code>taskflow2</code> will migrate the graph of <code>taskflow2</code> to <code>taskflow1</code>. After the move, <code>taskflow2</code> will become empty.</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span><span class="w"> </span><span class="nf">taskflow1</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">taskflow2</span><span class="p">));</span>
<span class="n">assert</span><span class="p">(</span><span class="n">taskflow2</span><span class="p">.</span><span class="n">empty</span><span class="p">());</span></pre><p>Notice that <code>taskflow2</code> should not be running in an executor during the move operation, or the behavior is undefined.</p>
          </div></section>
          <section class="m-doc-details" id="aa966a69493ecc8ecb9131ef3c5354b8e"><div>
            <h3>
              <span class="m-doc-wrap-bumper"> tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#aa966a69493ecc8ecb9131ef3c5354b8e" class="m-doc-self">~Taskflow</a>(</span><span class="m-doc-wrap">) <span class="m-label m-info">defaulted</span></span></span>
            </h3>
            <p>default destructor</p>
<p>When the destructor is called, all tasks and their associated data (e.g., captured data) will be destroyed. It is your responsibility to ensure all submitted execution of this taskflow have completed before destroying it. For instance, the following code results in undefined behavior since the executor may still be running the taskflow while it is destroyed after the block.</p><pre class="m-code"><span class="p">{</span>
<span class="w">  </span><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span><span class="w"> </span><span class="n">taskflow</span><span class="p">;</span>
<span class="w">  </span><span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">);</span>
<span class="p">}</span></pre><p>To fix the problem, we must wait for the execution to complete before destroying the taskflow.</p><pre class="m-code"><span class="p">{</span>
<span class="w">  </span><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span><span class="w"> </span><span class="n">taskflow</span><span class="p">;</span>
<span class="w">  </span><span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">).</span><span class="n">wait</span><span class="p">();</span>
<span class="p">}</span></pre>
          </div></section>
          <section class="m-doc-details" id="aa4957a41e63e1d1a6f77c540d70d04fa"><div>
            <h3>
              <span class="m-doc-wrap-bumper"><a href="classtf_1_1Taskflow.html" class="m-doc">Taskflow</a>&amp; tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#aa4957a41e63e1d1a6f77c540d70d04fa" class="m-doc-self">operator=</a>(</span><span class="m-doc-wrap"><a href="classtf_1_1Taskflow.html" class="m-doc">Taskflow</a>&amp;&amp; rhs)</span></span>
            </h3>
            <p>move assignment operator</p>
<p>Moving a taskflow <code>taskflow2</code> to another taskflow <code>taskflow1</code> will destroy the existing graph of <code>taskflow1</code> and assign it the graph of <code>taskflow2</code>. After the move, <code>taskflow2</code> will become empty.</p><pre class="m-code"><span class="n">taskflow1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">taskflow2</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">taskflow2</span><span class="p">.</span><span class="n">empty</span><span class="p">());</span></pre><p>Notice that both <code>taskflow1</code> and <code>taskflow2</code> should not be running in an executor during the move operation, or the behavior is undefined.</p>
          </div></section>
          <section class="m-doc-details" id="ac433018262e44b12c4cc9f0c4748d758"><div>
            <h3>
              <span class="m-doc-wrap-bumper">void tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#ac433018262e44b12c4cc9f0c4748d758" class="m-doc-self">dump</a>(</span><span class="m-doc-wrap"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html" class="m-doc-external">std::<wbr />ostream</a>&amp; ostream) const</span></span>
            </h3>
            <p>dumps the taskflow to a DOT format through a <a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html" class="m-doc-external">std::<wbr />ostream</a> target</p>
<pre class="m-code"><span class="n">taskflow</span><span class="p">.</span><span class="n">dump</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="p">);</span><span class="w">  </span><span class="c1">// dump the graph to the standard output</span>

<span class="n">std</span><span class="o">::</span><span class="n">ofstream</span><span class="w"> </span><span class="n">ofs</span><span class="p">(</span><span class="s">&quot;output.dot&quot;</span><span class="p">);</span>
<span class="n">taskflow</span><span class="p">.</span><span class="n">dump</span><span class="p">(</span><span class="n">ofs</span><span class="p">);</span><span class="w">        </span><span class="c1">// dump the graph to the file output.dot</span></pre><p>For dynamically spawned tasks, such as module tasks, subflow tasks, and GPU tasks, you need to run the taskflow first before you can dump the entire graph.</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Task</span><span class="w"> </span><span class="n">parent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](</span><span class="n">tf</span><span class="o">::</span><span class="n">Subflow</span><span class="w"> </span><span class="n">sf</span><span class="p">){</span>
<span class="w">  </span><span class="n">sf</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](){</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;child</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span><span class="w"> </span><span class="p">});</span>
<span class="p">});</span>
<span class="n">taskflow</span><span class="p">.</span><span class="n">dump</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="p">);</span><span class="w">      </span><span class="c1">// this dumps only the parent tasks</span>
<span class="n">executor</span><span class="p">.</span><span class="n">run</span><span class="p">(</span><span class="n">taskflow</span><span class="p">).</span><span class="n">wait</span><span class="p">();</span>
<span class="n">taskflow</span><span class="p">.</span><span class="n">dump</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="p">);</span><span class="w">      </span><span class="c1">// this dumps both parent and child tasks</span></pre>
          </div></section>
          <section class="m-doc-details" id="a9c4900da1831dce708664a06b3e3a3fb"><div>
            <h3>
              <span class="m-doc-wrap-bumper"><a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a> tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a9c4900da1831dce708664a06b3e3a3fb" class="m-doc-self">dump</a>(</span><span class="m-doc-wrap">) const</span></span>
            </h3>
            <p>dumps the taskflow to a <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a> of DOT format</p>
<p>This method is similar to tf::Taskflow::dump(std::ostream&amp; ostream), but returning a string of the graph in DOT format.</p>
          </div></section>
          <section class="m-doc-details" id="a224301842d94c44fd7fe99d8ac2ba241"><div>
            <h3>
              <span class="m-doc-wrap-bumper">bool tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a224301842d94c44fd7fe99d8ac2ba241" class="m-doc-self">empty</a>(</span><span class="m-doc-wrap">) const</span></span>
            </h3>
            <p>queries the emptiness of the taskflow</p>
<p>An empty taskflow has no tasks. That is the return of <a href="classtf_1_1Taskflow.html#af4f03bca084deb5c2228ac8936d33649" class="m-doc">tf::<wbr />Taskflow::<wbr />num_tasks</a> is zero.</p>
          </div></section>
          <section class="m-doc-details" id="ad5706e5819aa01a63c4aa2e3485546b9"><div>
            <h3>
              <span class="m-doc-wrap-bumper">void tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#ad5706e5819aa01a63c4aa2e3485546b9" class="m-doc-self">name</a>(</span><span class="m-doc-wrap">const <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a>&amp;)</span></span>
            </h3>
            <p>assigns a name to the taskflow</p>
<pre class="m-code"><span class="n">taskflow</span><span class="p">.</span><span class="n">name</span><span class="p">(</span><span class="s">&quot;assign another name&quot;</span><span class="p">);</span></pre>
          </div></section>
          <section class="m-doc-details" id="a911edd95acc1322433bddfcfeaf2ccb0"><div>
            <h3>
              <span class="m-doc-wrap-bumper">const <a href="http://en.cppreference.com/w/cpp/string/basic_string.html" class="m-doc-external">std::<wbr />string</a>&amp; tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a911edd95acc1322433bddfcfeaf2ccb0" class="m-doc-self">name</a>(</span><span class="m-doc-wrap">) const</span></span>
            </h3>
            <p>queries the name of the taskflow</p>
<pre class="m-code"><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;my name is: &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">name</span><span class="p">();</span></pre>
          </div></section>
          <section class="m-doc-details" id="a1f00bbe72a1553c9656ecae4d98bb9af"><div>
            <h3>
              <span class="m-doc-wrap-bumper">void tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a1f00bbe72a1553c9656ecae4d98bb9af" class="m-doc-self">clear</a>(</span><span class="m-doc-wrap">)</span></span>
            </h3>
            <p>clears the associated task dependency graph</p>
<p>When you clear a taskflow, all tasks and their associated data (e.g., captured data in task callables) will be destroyed. The behavior of clearing a running taskflow is undefined.</p>
          </div></section>
          <section class="m-doc-details" id="a6350d0d6653ae9ae7b94c35e42fffe07"><div>
            <h3>
              <div class="m-doc-template">
                template&lt;typename V&gt;
              </div>
              <span class="m-doc-wrap-bumper">void tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a6350d0d6653ae9ae7b94c35e42fffe07" class="m-doc-self">for_each_task</a>(</span><span class="m-doc-wrap">V&amp;&amp; visitor) const</span></span>
            </h3>
            <p>applies a visitor to each task in the taskflow</p>
<p>A visitor is a callable that takes an argument of type <a href="classtf_1_1Task.html" class="m-doc">tf::<wbr />Task</a> and returns nothing. The following example iterates each task in a taskflow and prints its name:</p><pre class="m-code"><span class="n">taskflow</span><span class="p">.</span><span class="n">for_each_task</span><span class="p">([](</span><span class="n">tf</span><span class="o">::</span><span class="n">Task</span><span class="w"> </span><span class="n">task</span><span class="p">){</span>
<span class="w">  </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">task</span><span class="p">.</span><span class="n">name</span><span class="p">()</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>
<span class="p">});</span></pre>
          </div></section>
          <section class="m-doc-details" id="a354a7673fabeaf3be66928ad6b573900"><div>
            <h3>
              <span class="m-doc-wrap-bumper">void tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a354a7673fabeaf3be66928ad6b573900" class="m-doc-self">remove_dependency</a>(</span><span class="m-doc-wrap"><a href="classtf_1_1Task.html" class="m-doc">Task</a> from,
              <a href="classtf_1_1Task.html" class="m-doc">Task</a> to)</span></span>
            </h3>
            <p>removes dependencies that go from task <code>from</code> to task <code>to</code></p>
            <table class="m-table m-fullwidth m-flat">
              <thead>
                <tr><th colspan="2">Parameters</th></tr>
              </thead>
              <tbody>
                <tr>
                  <td style="width: 1%">from</td>
                  <td>from task (dependent)</td>
                </tr>
                <tr>
                  <td>to</td>
                  <td>to task (successor)</td>
                </tr>
              </tbody>
            </table>
<pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span><span class="w"> </span><span class="n">taskflow</span><span class="p">;</span>
<span class="k">auto</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">placeholder</span><span class="p">().</span><span class="n">name</span><span class="p">(</span><span class="s">&quot;a&quot;</span><span class="p">);</span>
<span class="k">auto</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">placeholder</span><span class="p">().</span><span class="n">name</span><span class="p">(</span><span class="s">&quot;b&quot;</span><span class="p">);</span>
<span class="k">auto</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">placeholder</span><span class="p">().</span><span class="n">name</span><span class="p">(</span><span class="s">&quot;c&quot;</span><span class="p">);</span>
<span class="k">auto</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">taskflow</span><span class="p">.</span><span class="n">placeholder</span><span class="p">().</span><span class="n">name</span><span class="p">(</span><span class="s">&quot;d&quot;</span><span class="p">);</span>

<span class="n">a</span><span class="p">.</span><span class="n">precede</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="n">d</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">num_successors</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">3</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">num_dependents</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">c</span><span class="p">.</span><span class="n">num_dependents</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">d</span><span class="p">.</span><span class="n">num_dependents</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>

<span class="n">taskflow</span><span class="p">.</span><span class="n">remove_dependency</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">num_successors</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span>
<span class="n">assert</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">num_dependents</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span></pre>
          </div></section>
          <section class="m-doc-details" id="a8da984d149b439e88468bf26e02ecf27"><div>
            <h3>
              <span class="m-doc-wrap-bumper"><a href="classtf_1_1Graph.html" class="m-doc">Graph</a>&amp; tf::<wbr />Taskflow::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a8da984d149b439e88468bf26e02ecf27" class="m-doc-self">graph</a>(</span><span class="m-doc-wrap">)</span></span>
            </h3>
            <p>returns a reference to the underlying graph object</p>
<p>A graph object (of type <a href="classtf_1_1Graph.html" class="m-doc">tf::<wbr />Graph</a>) is the ultimate storage for the task dependency graph and should only be used as an opaque data structure to interact with the executor (e.g., composition).</p>
          </div></section>
        </section>
      </div>
    </div>
  </div>
</article></main>
<div class="m-doc-search" id="search">
  <a href="#!" onclick="return hideSearch()"></a>
  <div class="m-container">
    <div class="m-row">
      <div class="m-col-m-8 m-push-m-2">
        <div class="m-doc-search-header m-text m-small">
          <div><span class="m-label m-default">Tab</span> / <span class="m-label m-default">T</span> to search, <span class="m-label m-default">Esc</span> to close</div>
          <div id="search-symbolcount">&hellip;</div>
        </div>
        <div class="m-doc-search-content">
          <form>
            <input type="search" name="q" id="search-input" placeholder="Loading &hellip;" disabled="disabled" autofocus="autofocus" autocomplete="off" spellcheck="false" />
          </form>
          <noscript class="m-text m-danger m-text-center">Unlike everything else in the docs, the search functionality <em>requires</em> JavaScript.</noscript>
          <div id="search-help" class="m-text m-dim m-text-center">
            <p class="m-noindent">Search for symbols, directories, files, pages or
            modules. You can omit any prefix from the symbol or file path; adding a
            <code>:</code> or <code>/</code> suffix lists all members of given symbol or
            directory.</p>
            <p class="m-noindent">Use <span class="m-label m-dim">&darr;</span>
            / <span class="m-label m-dim">&uarr;</span> to navigate through the list,
            <span class="m-label m-dim">Enter</span> to go.
            <span class="m-label m-dim">Tab</span> autocompletes common prefix, you can
            copy a link to the result using <span class="m-label m-dim">⌘</span>
            <span class="m-label m-dim">L</span> while <span class="m-label m-dim">⌘</span>
            <span class="m-label m-dim">M</span> produces a Markdown link.</p>
          </div>
          <div id="search-notfound" class="m-text m-warning m-text-center">Sorry, nothing was found.</div>
          <ul id="search-results"></ul>
        </div>
      </div>
    </div>
  </div>
</div>
<script src="search-v2.js"></script>
<script src="searchdata-v2.js" async="async"></script>
<footer><nav>
  <div class="m-container">
    <div class="m-row">
      <div class="m-col-l-10 m-push-l-1">
        <p>Taskflow handbook is part of the <a href="https://taskflow.github.io">Taskflow project</a>, copyright © <a href="https://tsung-wei-huang.github.io/">Dr. Tsung-Wei Huang</a>, 2018&ndash;2024.<br />Generated by <a href="https://doxygen.org/">Doxygen</a> 1.9.6 and <a href="https://mcss.mosra.cz/">m.css</a>.</p>
      </div>
    </div>
  </div>
</nav></footer>
</body>
</html>
